//
//  WbVisitorController.swift
//  Weibo
//
//  Created by HH on 16/12/1.
//  Copyright © 2016年 Weibo. All rights reserved.
//

import UIKit

class WbVisitorController: UITableViewController {
    
    var isLogin:Bool = WbUserAccountViewModel.sharedUserAccount.isLogin
    lazy var visitorView:WbVisitorView? = WbVisitorView()
    
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        

    }
    
    override func loadView() {
        
        if isLogin {
            
            super.loadView()
            
        }else{
            view = visitorView
            
            //注意!!!这个要放到没有登录的里面
            setupNavUI()
            
            visitorView?.callBack = { [weak self]  (result) in
                
                if result == LoginOrSignUp.Login {
                    self?.requestOauth()
                }else{
                    self?.requestOauth()
                }
            }
        }
    }
    
    func setupNavUI(){
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", imageName: nil, target: self, selector: #selector(loginAction(sender:)))
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", imageName: nil, target: self, selector: #selector(signUpAction(sender:)))
    }
    
    @objc private func loginAction(sender:UIButton){
        
        print("登录")
        requestOauth()
        
    }
    
    @objc private func signUpAction(sender:UIButton){
        print("注册")
        
        requestOauth()
    }
    
    private func requestOauth(){
        
        let oauthController = WbOauthController()
        
        let navController = WbNavigationController(rootViewController: oauthController)
        
        
        present(navController, animated: true, completion: nil)
    }


    func setupUI(){
        
    }

}
